import Vue from 'vue'
import Router from 'vue-router'
import Recommend from '@/pages/recommend/recommend'
import Rank from '@/pages/rank/rank'
import Search from '@/pages/search/search'
import Test from '@/pages/test/test'

Vue.use(Router)

// 使用路由懒加载会有个bug：首次进入的时候推荐页面是从右边进来的
// const Recommend = (resolve) => {
//   import('@/pages/recommend/recommend').then((module) => {
//     resolve(module)
//   })
// }
// const Rank = (resolve) => {
//   import('@/pages/rank/rank').then((module) => {
//     resolve(module)
//   })
// }
// const Search = (resolve) => {
//   import('@/pages/search/search').then((module) => {
//     resolve(module)
//   })
// }
// const Test = (resolve) => {
//   import('@/pages/test/test').then((module) => {
//     resolve(module)
//   })
// }

export default new Router({
  routes: [
    {
      path: '/',
      redirect: '/recommend'
    },
    {
      path: '/recommend',
      name: 'Recommend',
      component: Recommend,
      meta: { index: 1 },
      children: [{
        path: ':id',
        name: 'Test',
        component: Test
      }]
    },
    {
      path: '/rank',
      name: 'Rank',
      component: Rank,
      meta: { index: 2 }
    },
    {
      path: '/search',
      name: 'Search',
      component: Search,
      meta: { index: 3 }
    }
  ]
})
